
<!doctype html>
<html lang="en" class="no-js">
  <head>
    
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width,initial-scale=1">
      
        <meta name="description" content="DrissionPage是个网页自动化工具。既能控制浏览器，也能收发数据包。可兼顾便利性和高效率。功能强大，语法简洁优雅。">
      
      
        <meta name="author" content="g1879">
      
      
        <link rel="canonical" href="http://g1879.gitee.io/DrissionPageDocs/whatsnew/4_0/">
      
      
        <link rel="prev" href="../..">
      
      
        <link rel="next" href="../3_2/">
      
      <link rel="icon" href="../../imgs/logo.png">
      <meta name="generator" content="mkdocs-1.4.3, mkdocs-material-9.1.16">
    
    
      
        <title>💥 4.0 功能介绍 - DrissionPage</title>
      
    
    
      <link rel="stylesheet" href="../../assets/stylesheets/main.26e3688c.min.css">
      
        
        <link rel="stylesheet" href="../../assets/stylesheets/palette.ecc896b0.min.css">
      
      
  
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
    
    
  
  
  <style>:root{--md-admonition-icon--note:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M1 7.775V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 0 1 0 2.474l-5.026 5.026a1.75 1.75 0 0 1-2.474 0l-6.25-6.25A1.752 1.752 0 0 1 1 7.775Zm1.5 0c0 .066.026.13.073.177l6.25 6.25a.25.25 0 0 0 .354 0l5.025-5.025a.25.25 0 0 0 0-.354l-6.25-6.25a.25.25 0 0 0-.177-.073H2.75a.25.25 0 0 0-.25.25ZM6 5a1 1 0 1 1 0 2 1 1 0 0 1 0-2Z"/></svg>');--md-admonition-icon--abstract:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M2.5 1.75v11.5c0 .138.112.25.25.25h3.17a.75.75 0 0 1 0 1.5H2.75A1.75 1.75 0 0 1 1 13.25V1.75C1 .784 1.784 0 2.75 0h8.5C12.216 0 13 .784 13 1.75v7.736a.75.75 0 0 1-1.5 0V1.75a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13.274 9.537v-.001l-4.557 4.45a.75.75 0 0 1-1.055-.008l-1.943-1.95a.75.75 0 0 1 1.062-1.058l1.419 1.425 4.026-3.932a.75.75 0 1 1 1.048 1.074ZM4.75 4h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM4 7.75A.75.75 0 0 1 4.75 7h2a.75.75 0 0 1 0 1.5h-2A.75.75 0 0 1 4 7.75Z"/></svg>');--md-admonition-icon--info:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.5 7.75A.75.75 0 0 1 7.25 7h1a.75.75 0 0 1 .75.75v2.75h.25a.75.75 0 0 1 0 1.5h-2a.75.75 0 0 1 0-1.5h.25v-2h-.25a.75.75 0 0 1-.75-.75ZM8 6a1 1 0 1 1 0-2 1 1 0 0 1 0 2Z"/></svg>');--md-admonition-icon--tip:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M3.499.75a.75.75 0 0 1 1.5 0v.996C5.9 2.903 6.793 3.65 7.662 4.376l.24.202c-.036-.694.055-1.422.426-2.163C9.1.873 10.794-.045 12.622.26 14.408.558 16 1.94 16 4.25c0 1.278-.954 2.575-2.44 2.734l.146.508.065.22c.203.701.412 1.455.476 2.226.142 1.707-.4 3.03-1.487 3.898C11.714 14.671 10.27 15 8.75 15h-6a.75.75 0 0 1 0-1.5h1.376a4.484 4.484 0 0 1-.563-1.191 3.835 3.835 0 0 1-.05-2.063 4.647 4.647 0 0 1-2.025-.293.75.75 0 0 1 .525-1.406c1.357.507 2.376-.006 2.698-.318l.009-.01a.747.747 0 0 1 1.06 0 .748.748 0 0 1-.012 1.074c-.912.92-.992 1.835-.768 2.586.221.74.745 1.337 1.196 1.621H8.75c1.343 0 2.398-.296 3.074-.836.635-.507 1.036-1.31.928-2.602-.05-.603-.216-1.224-.422-1.93l-.064-.221c-.12-.407-.246-.84-.353-1.29a2.425 2.425 0 0 1-.507-.441 3.075 3.075 0 0 1-.633-1.248.75.75 0 0 1 1.455-.364c.046.185.144.436.31.627.146.168.353.305.712.305.738 0 1.25-.615 1.25-1.25 0-1.47-.95-2.315-2.123-2.51-1.172-.196-2.227.387-2.706 1.345-.46.92-.27 1.774.019 3.062l.042.19a.884.884 0 0 1 .01.05c.348.443.666.949.94 1.553a.75.75 0 1 1-1.365.62c-.553-1.217-1.32-1.94-2.3-2.768L6.7 5.527c-.814-.68-1.75-1.462-2.692-2.619a3.737 3.737 0 0 0-1.023.88c-.406.495-.663 1.036-.722 1.508.116.122.306.21.591.239.388.038.797-.06 1.032-.19a.75.75 0 0 1 .728 1.31c-.515.287-1.23.439-1.906.373-.682-.067-1.473-.38-1.879-1.193L.75 5.677V5.5c0-.984.48-1.94 1.077-2.664.46-.559 1.05-1.055 1.673-1.353V.75Z"/></svg>');--md-admonition-icon--success:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M13.78 4.22a.75.75 0 0 1 0 1.06l-7.25 7.25a.75.75 0 0 1-1.06 0L2.22 9.28a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018L6 10.94l6.72-6.72a.75.75 0 0 1 1.06 0Z"/></svg>');--md-admonition-icon--question:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8Zm8-6.5a6.5 6.5 0 1 0 0 13 6.5 6.5 0 0 0 0-13ZM6.92 6.085h.001a.749.749 0 1 1-1.342-.67c.169-.339.436-.701.849-.977C6.845 4.16 7.369 4 8 4a2.756 2.756 0 0 1 1.637.525c.503.377.863.965.863 1.725 0 .448-.115.83-.329 1.15-.205.307-.47.513-.692.662-.109.072-.22.138-.313.195l-.006.004a6.24 6.24 0 0 0-.26.16.952.952 0 0 0-.276.245.75.75 0 0 1-1.248-.832c.184-.264.42-.489.692-.661.103-.067.207-.132.313-.195l.007-.004c.1-.061.182-.11.258-.161a.969.969 0 0 0 .277-.245C8.96 6.514 9 6.427 9 6.25a.612.612 0 0 0-.262-.525A1.27 1.27 0 0 0 8 5.5c-.369 0-.595.09-.74.187a1.01 1.01 0 0 0-.34.398ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>');--md-admonition-icon--warning:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M6.457 1.047c.659-1.234 2.427-1.234 3.086 0l6.082 11.378A1.75 1.75 0 0 1 14.082 15H1.918a1.75 1.75 0 0 1-1.543-2.575Zm1.763.707a.25.25 0 0 0-.44 0L1.698 13.132a.25.25 0 0 0 .22.368h12.164a.25.25 0 0 0 .22-.368Zm.53 3.996v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 11a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"/></svg>');--md-admonition-icon--failure:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M2.344 2.343h-.001a8 8 0 0 1 11.314 11.314A8.002 8.002 0 0 1 .234 10.089a8 8 0 0 1 2.11-7.746Zm1.06 10.253a6.5 6.5 0 1 0 9.108-9.275 6.5 6.5 0 0 0-9.108 9.275ZM6.03 4.97 8 6.94l1.97-1.97a.749.749 0 0 1 1.275.326.749.749 0 0 1-.215.734L9.06 8l1.97 1.97a.749.749 0 0 1-.326 1.275.749.749 0 0 1-.734-.215L8 9.06l-1.97 1.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734L6.94 8 4.97 6.03a.751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018Z"/></svg>');--md-admonition-icon--danger:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M9.504.43a1.516 1.516 0 0 1 2.437 1.713L10.415 5.5h2.123c1.57 0 2.346 1.909 1.22 3.004l-7.34 7.142a1.249 1.249 0 0 1-.871.354h-.302a1.25 1.25 0 0 1-1.157-1.723L5.633 10.5H3.462c-1.57 0-2.346-1.909-1.22-3.004L9.503.429Zm1.047 1.074L3.286 8.571A.25.25 0 0 0 3.462 9H6.75a.75.75 0 0 1 .694 1.034l-1.713 4.188 6.982-6.793A.25.25 0 0 0 12.538 7H9.25a.75.75 0 0 1-.683-1.06l2.008-4.418.003-.006a.036.036 0 0 0-.004-.009l-.006-.006-.008-.001c-.003 0-.006.002-.009.004Z"/></svg>');--md-admonition-icon--bug:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M4.72.22a.75.75 0 0 1 1.06 0l1 .999a3.488 3.488 0 0 1 2.441 0l.999-1a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.775.776c.616.63.995 1.493.995 2.444v.327c0 .1-.009.197-.025.292.408.14.764.392 1.029.722l1.968-.787a.75.75 0 0 1 .556 1.392L13 7.258V9h2.25a.75.75 0 0 1 0 1.5H13v.5c0 .409-.049.806-.141 1.186l2.17.868a.75.75 0 0 1-.557 1.392l-2.184-.873A4.997 4.997 0 0 1 8 16a4.997 4.997 0 0 1-4.288-2.427l-2.183.873a.75.75 0 0 1-.558-1.392l2.17-.868A5.036 5.036 0 0 1 3 11v-.5H.75a.75.75 0 0 1 0-1.5H3V7.258L.971 6.446a.75.75 0 0 1 .558-1.392l1.967.787c.265-.33.62-.583 1.03-.722a1.677 1.677 0 0 1-.026-.292V4.5c0-.951.38-1.814.995-2.444L4.72 1.28a.75.75 0 0 1 0-1.06Zm.53 6.28a.75.75 0 0 0-.75.75V11a3.5 3.5 0 1 0 7 0V7.25a.75.75 0 0 0-.75-.75ZM6.173 5h3.654A.172.172 0 0 0 10 4.827V4.5a2 2 0 1 0-4 0v.327c0 .096.077.173.173.173Z"/></svg>');--md-admonition-icon--example:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M5 5.782V2.5h-.25a.75.75 0 0 1 0-1.5h6.5a.75.75 0 0 1 0 1.5H11v3.282l3.666 5.76C15.619 13.04 14.543 15 12.767 15H3.233c-1.776 0-2.852-1.96-1.899-3.458Zm-2.4 6.565a.75.75 0 0 0 .633 1.153h9.534a.75.75 0 0 0 .633-1.153L12.225 10.5h-8.45ZM9.5 2.5h-3V6c0 .143-.04.283-.117.403L4.73 9h6.54L9.617 6.403A.746.746 0 0 1 9.5 6Z"/></svg>');--md-admonition-icon--quote:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M1.75 2.5h10.5a.75.75 0 0 1 0 1.5H1.75a.75.75 0 0 1 0-1.5Zm4 5h8.5a.75.75 0 0 1 0 1.5h-8.5a.75.75 0 0 1 0-1.5Zm0 5h8.5a.75.75 0 0 1 0 1.5h-8.5a.75.75 0 0 1 0-1.5ZM2.5 7.75v6a.75.75 0 0 1-1.5 0v-6a.75.75 0 0 1 1.5 0Z"/></svg>');}</style>


    
    
    
      
        
        
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CRoboto+Mono:400,400i,700,700i&display=fallback">
        <style>:root{--md-text-font:"Roboto";--md-code-font:"Roboto Mono"}</style>
      
    
    
    <script>__md_scope=new URL("../..",location),__md_hash=e=>[...e].reduce((e,_)=>(e<<5)-e+_.charCodeAt(0),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
    
      

    
    
    
  </head>
  
  
    
    
      
    
    
    
    
    <body dir="ltr" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo">
  
    
    
      <script>var palette=__md_get("__palette");if(palette&&"object"==typeof palette.color)for(var key of Object.keys(palette.color))document.body.setAttribute("data-md-color-"+key,palette.color[key])</script>
    
    <input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
    <input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
    <label class="md-overlay" for="__drawer"></label>
    <div data-md-component="skip">
      
        
        <a href="#_1" class="md-skip">
          Skip to content
        </a>
      
    </div>
    <div data-md-component="announce">
      
    </div>
    
    
      

  

<header class="md-header md-header--shadow md-header--lifted" data-md-component="header">
  <nav class="md-header__inner md-grid" aria-label="Header">
    <a href="../.." title="DrissionPage" class="md-header__button md-logo" aria-label="DrissionPage" data-md-component="logo">
      
  <img src="../../imgs/logo.png" alt="logo">

    </a>
    <label class="md-header__button md-icon" for="__drawer">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2Z"/></svg>
    </label>
    <div class="md-header__title" data-md-component="header-title">
      <div class="md-header__ellipsis">
        <div class="md-header__topic">
          <span class="md-ellipsis">
            DrissionPage
          </span>
        </div>
        <div class="md-header__topic" data-md-component="header-topic">
          <span class="md-ellipsis">
            
              💥 4.0 功能介绍
            
          </span>
        </div>
      </div>
    </div>
    
      
        <form class="md-header__option" data-md-component="palette">
          
            
            
            
            <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="slate" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to dark mode"  type="radio" name="__palette" id="__palette_1">
            
              <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
            
            
            
            <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo"  aria-label="Switch to light mode"  type="radio" name="__palette" id="__palette_2">
            
              <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1" hidden>
                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12c0-2.42-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12 20 8.69Z"/></svg>
              </label>
            
          
        </form>
      
    
    
    
      <label class="md-header__button md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
      </label>
      <div class="md-search" data-md-component="search" role="dialog">
  <label class="md-search__overlay" for="__search"></label>
  <div class="md-search__inner" role="search">
    <form class="md-search__form" name="search">
      <input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
      <label class="md-search__icon md-icon" for="__search">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5Z"/></svg>
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
      </label>
      <nav class="md-search__options" aria-label="Search">
        
        <button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41Z"/></svg>
        </button>
      </nav>
      
    </form>
    <div class="md-search__output">
      <div class="md-search__scrollwrap" data-md-scrollfix>
        <div class="md-search-result" data-md-component="search-result">
          <div class="md-search-result__meta">
            Initializing search
          </div>
          <ol class="md-search-result__list" role="presentation"></ol>
        </div>
      </div>
    </div>
  </div>
</div>
    
    
      <div class="md-header__source">
        <a href="https://gitee.com/g1879/DrissionPage" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
  </div>
  <div class="md-source__repository">
    Gitee
  </div>
</a>
      </div>
    
  </nav>
  
    
      
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
  <div class="md-grid">
    <ul class="md-tabs__list">
      
        
  
  


  <li class="md-tabs__item">
    <a href="../.." class="md-tabs__link">
      欢迎
    </a>
  </li>

      
        
  
  
    
  


  
  
  
    <li class="md-tabs__item">
      <a href="./" class="md-tabs__link md-tabs__link--active">
        🔥 新版介绍
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../get_start/installation/" class="md-tabs__link">
        入门指南
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../usage_introduction/" class="md-tabs__link">
        使用文档
      </a>
    </li>
  

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../demos/login_gitee/" class="md-tabs__link">
        示例和技巧
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../Q%26A/" class="md-tabs__link">
      常见问题
    </a>
  </li>

      
        
  
  


  
  
  
    <li class="md-tabs__item">
      <a href="../../history/introduction/" class="md-tabs__link">
        版本历史
      </a>
    </li>
  

      
        
  
  


  <li class="md-tabs__item">
    <a href="https://gitee.com/g1879/DrissionPage/issues" class="md-tabs__link">
      意见建议
    </a>
  </li>

      
        
  
  


  <li class="md-tabs__item">
    <a href="../../cooperation/" class="md-tabs__link">
      商业合作
    </a>
  </li>

      
    </ul>
  </div>
</nav>
    
  
</header>
    
    <div class="md-container" data-md-component="container">
      
      
        
      
      <main class="md-main" data-md-component="main">
        <div class="md-main__inner md-grid">
          
            
              
              <div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

  


<nav class="md-nav md-nav--primary md-nav--lifted" aria-label="Navigation" data-md-level="0">
  <label class="md-nav__title" for="__drawer">
    <a href="../.." title="DrissionPage" class="md-nav__button md-logo" aria-label="DrissionPage" data-md-component="logo">
      
  <img src="../../imgs/logo.png" alt="logo">

    </a>
    DrissionPage
  </label>
  
    <div class="md-nav__source">
      <a href="https://gitee.com/g1879/DrissionPage" title="Go to repository" class="md-source" data-md-component="source">
  <div class="md-source__icon md-icon">
    
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.4.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc.--><path d="M439.55 236.05 244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z"/></svg>
  </div>
  <div class="md-source__repository">
    Gitee
  </div>
</a>
    </div>
  
  <ul class="md-nav__list" data-md-scrollfix>
    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../.." class="md-nav__link">
        欢迎
      </a>
    </li>
  

    
      
      
      

  
  
    
  
  
    
    <li class="md-nav__item md-nav__item--active md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2" checked>
      
      
      
        <label class="md-nav__link" for="__nav_2" id="__nav_2_label" tabindex="0">
          🔥 新版介绍
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_2_label" aria-expanded="true">
        <label class="md-nav__title" for="__nav_2">
          <span class="md-nav__icon md-icon"></span>
          🔥 新版介绍
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
    
  
  
    <li class="md-nav__item md-nav__item--active">
      
      <input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
      
      
      
        <label class="md-nav__link md-nav__link--active" for="__toc">
          💥 4.0 功能介绍
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <a href="./" class="md-nav__link md-nav__link--active">
        💥 4.0 功能介绍
      </a>
      
        

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    ✅️ 新的抓包功能
  </a>
  
    <nav class="md-nav" aria-label="✅️ 新的抓包功能">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#api" class="md-nav__link">
    📌 旧 api 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#api_1" class="md-nav__link">
    📌 新 api
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    📌 示例
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    ✅️ 新的页面访问逻辑
  </a>
  
    <nav class="md-nav" aria-label="✅️ 新的页面访问逻辑">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#api_2" class="md-nav__link">
    📌 api 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_4" class="md-nav__link">
    📌 行为变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#none" class="md-nav__link">
    📌 新的none加载模式
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_5" class="md-nav__link">
    📌 示例
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_6" class="md-nav__link">
    ✅️ 新的下载管理功能
  </a>
  
    <nav class="md-nav" aria-label="✅️ 新的下载管理功能">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#api_3" class="md-nav__link">
    📌 api 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_7" class="md-nav__link">
    📌 新增功能
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_8" class="md-nav__link">
    📌 行为变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_9" class="md-nav__link">
    📌 示例
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_10" class="md-nav__link">
    ✅️ 页面对象
  </a>
  
    <nav class="md-nav" aria-label="✅️ 页面对象">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_11" class="md-nav__link">
    📌 启动参数变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_12" class="md-nav__link">
    📌 内置动作链
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_13" class="md-nav__link">
    📌 状态信息
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_14" class="md-nav__link">
    📌 其它
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#cookies" class="md-nav__link">
    ✅️ cookies 设置
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_15" class="md-nav__link">
    ✅️ 标签页管理
  </a>
  
    <nav class="md-nav" aria-label="✅️ 标签页管理">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#to_tab" class="md-nav__link">
    📌 不再支持to_tab()功能
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#new_tab" class="md-nav__link">
    📌 new_tab()的新功能
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_16" class="md-nav__link">
    📌 标签页的位置与大小
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_17" class="md-nav__link">
    📌 标签页的行为
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#get_tab" class="md-nav__link">
    📌 get_tab()参数变化
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_18" class="md-nav__link">
    ✅️ 元素相关
  </a>
  
    <nav class="md-nav" aria-label="✅️ 元素相关">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_19" class="md-nav__link">
    📌 定位语法变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_20" class="md-nav__link">
    📌 相对定位参数优化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_21" class="md-nav__link">
    📌 位置和大小
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_22" class="md-nav__link">
    📌 点击
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_23" class="md-nav__link">
    📌 查找元素失败显示细节
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_24" class="md-nav__link">
    📌 设置查找失败元素返回默认值
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_25" class="md-nav__link">
    📌 更多
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_26" class="md-nav__link">
    ✅️ 启动配置
  </a>
  
    <nav class="md-nav" aria-label="✅️ 启动配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#easy_set" class="md-nav__link">
    📌 删除 easy_set 方法
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_27" class="md-nav__link">
    📌 支持设置实验项
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#ini" class="md-nav__link">
    📌 ini 文件变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#chromiumoptions" class="md-nav__link">
    📌 ChromiumOptions 修改
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#sessionoptions" class="md-nav__link">
    📌 SessionOptions 修改
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_28" class="md-nav__link">
    📌 其它
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_29" class="md-nav__link">
    ✅️ 其它
  </a>
  
    <nav class="md-nav" aria-label="✅️ 其它">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#2x" class="md-nav__link">
    📌 删除 2.x 代码
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_30" class="md-nav__link">
    📌 异常变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#settings" class="md-nav__link">
    📌 Settings 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_31" class="md-nav__link">
    📌 更多
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_32" class="md-nav__link">
    ✅️ 问题修复
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_33" class="md-nav__link">
    ✅️ 下一步计划
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_34" class="md-nav__link">
    ✅️ 加快开发进度
  </a>
  
</li>
      
    </ul>
  
</nav>
      
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../3_2/" class="md-nav__link">
        💥 3.2 功能介绍
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3" >
      
      
      
        <label class="md-nav__link" for="__nav_3" id="__nav_3_label" tabindex="0">
          入门指南
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_3_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3">
          <span class="md-nav__icon md-icon"></span>
          入门指南
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/installation/" class="md-nav__link">
        🌏 安装
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/import/" class="md-nav__link">
        🌏 导入
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/before_start/" class="md-nav__link">
        🌏 准备工作
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_4" >
      
      
      
        <label class="md-nav__link" for="__nav_3_4" id="__nav_3_4_label" tabindex="0">
          🌏 上手示例
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_4_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3_4">
          <span class="md-nav__icon md-icon"></span>
          🌏 上手示例
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/examples/control_browser/" class="md-nav__link">
        🗺️ 操控浏览器
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/examples/data_packets/" class="md-nav__link">
        🗺️ 收发数据包
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/examples/switch_mode/" class="md-nav__link">
        🗺️ 模式切换
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_start/basic_concept/" class="md-nav__link">
        ☀️ 基本概念
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_6" >
      
      
      
        <label class="md-nav__link" for="__nav_3_6" id="__nav_3_6_label" tabindex="0">
          ☀️ 特性和亮点
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_3_6_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3_6">
          <span class="md-nav__icon md-icon"></span>
          ☀️ 特性和亮点
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/intimate_design/" class="md-nav__link">
        💖 贴心设计
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_3_6_2" >
      
      
      
        <label class="md-nav__link" for="__nav_3_6_2" id="__nav_3_6_2_label" tabindex="0">
          🌟 特性演示
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="3" aria-labelledby="__nav_3_6_2_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_3_6_2">
          <span class="md-nav__icon md-icon"></span>
          🌟 特性演示
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/features_demos/compare_with_requests/" class="md-nav__link">
        ⭐ 与 requests 对比
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/features_demos/compare_with_selenium/" class="md-nav__link">
        ⭐ 与 selenium 对比
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/features_demos/switch_mode/" class="md-nav__link">
        ⭐ 模式切换
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/features_demos/get_element_attributes/" class="md-nav__link">
        ⭐ 获取元素属性
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../features/features_demos/download_file/" class="md-nav__link">
        ⭐ 下载文件
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4" >
      
      
      
        <label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
          使用文档
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4">
          <span class="md-nav__icon md-icon"></span>
          使用文档
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../usage_introduction/" class="md-nav__link">
        💬 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_2" >
      
      
      
        <label class="md-nav__link" for="__nav_4_2" id="__nav_4_2_label" tabindex="0">
          🚅 SessionPage
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_2_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4_2">
          <span class="md-nav__icon md-icon"></span>
          🚅 SessionPage
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/introduction/" class="md-nav__link">
        🚄 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/create_page_object/" class="md-nav__link">
        🚄 创建页面对象
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/visit_web_page/" class="md-nav__link">
        🚄 访问网页
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/get_page_info/" class="md-nav__link">
        🚄 获取网页信息
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/introduction/" class="md-nav__link">
        🚄 查找元素
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/get_element_info/" class="md-nav__link">
        🚄 获取元素信息
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/set_session/" class="md-nav__link">
        🚄 页面设置
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../SessionPge/session_options/" class="md-nav__link">
        🚄 启动配置
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_3" >
      
      
      
        <label class="md-nav__link" for="__nav_4_3" id="__nav_4_3_label" tabindex="0">
          🛳️ ChromiumPage
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_3_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4_3">
          <span class="md-nav__icon md-icon"></span>
          🛳️ ChromiumPage
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/introduction/" class="md-nav__link">
        🚤 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/create_page_object/" class="md-nav__link">
        🚤 创建页面对象
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/visit_web_page/" class="md-nav__link">
        🚤 访问网页
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/get_page_info/" class="md-nav__link">
        🚤 获取网页信息
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/page_operation/" class="md-nav__link">
        🚤 页面交互
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/introduction/" class="md-nav__link">
        🚤 查找元素
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/get_element_info/" class="md-nav__link">
        🚤 获取元素信息
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/element_operation/" class="md-nav__link">
        🚤 元素交互
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/waiting/" class="md-nav__link">
        🚤 自动等待
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/upload_files/" class="md-nav__link">
        🚤 文件上传
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/tab_operation/" class="md-nav__link">
        🚤 标签页操作
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/frame_operation/" class="md-nav__link">
        🚤 iframe 操作
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/network_listener/" class="md-nav__link">
        🚤 监听网络数据
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/actions/" class="md-nav__link">
        🚤 动作链
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/screen_recording/" class="md-nav__link">
        🚤 截图和录像
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../ChromiumPage/browser_options/" class="md-nav__link">
        🚤 浏览器启动配置
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_4" >
      
      
      
        <label class="md-nav__link" for="__nav_4_4" id="__nav_4_4_label" tabindex="0">
          🚀 WebPage
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_4_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4_4">
          <span class="md-nav__icon md-icon"></span>
          🚀 WebPage
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../WebPage/introduction/" class="md-nav__link">
        🛸 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../WebPage/create_page_object/" class="md-nav__link">
        🛸 创建页面对象
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../WebPage/mode_switch/" class="md-nav__link">
        🛸 模式切换
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../WebPage/webpage_function/" class="md-nav__link">
        🛸 独有的功能
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_5" >
      
      
      
        <label class="md-nav__link" for="__nav_4_5" id="__nav_4_5_label" tabindex="0">
          🔎 查找元素
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_5_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4_5">
          <span class="md-nav__icon md-icon"></span>
          🔎 查找元素
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/introduction/" class="md-nav__link">
        🔦 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/usage/" class="md-nav__link">
        🔦 基本用法
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/more/" class="md-nav__link">
        🔦 更多用法
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/simplify/" class="md-nav__link">
        🔦 简便写法
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/not_found/" class="md-nav__link">
        🔦 找不到元素时
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../get_elements/cheat_sheet/" class="md-nav__link">
        🔦 语法速查表
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_6" >
      
      
      
        <label class="md-nav__link" for="__nav_4_6" id="__nav_4_6_label" tabindex="0">
          ⬇️ 下载文件
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_6_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4_6">
          <span class="md-nav__icon md-icon"></span>
          ⬇️ 下载文件
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../download/introduction/" class="md-nav__link">
        ↘️ 概述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../download/DownloadKit/" class="md-nav__link">
        ↘️ DownloadKit
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../download/browser/" class="md-nav__link">
        ↘️ 浏览器下载任务
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_4_7" >
      
      
      
        <label class="md-nav__link" for="__nav_4_7" id="__nav_4_7_label" tabindex="0">
          🧰 进阶使用
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_7_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_4_7">
          <span class="md-nav__icon md-icon"></span>
          🧰 进阶使用
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../advance/ini_file/" class="md-nav__link">
        ⚙️ 配置文件的使用
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../advance/settings/" class="md-nav__link">
        ⚙️ 全局运行设置
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../advance/errors/" class="md-nav__link">
        ⚙️ 异常的使用
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../advance/commands/" class="md-nav__link">
        ⚙️ 命令行的使用
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../advance/accelerate_collecting/" class="md-nav__link">
        ⚙️ 加速浏览器数据采集
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../advance/packaging/" class="md-nav__link">
        ⚙️ 打包程序
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../MixPage/introduction/" class="md-nav__link">
        🛠 旧版（MixPage）
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_5" >
      
      
      
        <label class="md-nav__link" for="__nav_5" id="__nav_5_label" tabindex="0">
          示例和技巧
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_5_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_5">
          <span class="md-nav__icon md-icon"></span>
          示例和技巧
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../demos/login_gitee/" class="md-nav__link">
        🌠 自动登录码云
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../demos/maoyan_TOP100/" class="md-nav__link">
        🌠 采集猫眼电影 TOP100 榜
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../demos/starbucks_pics/" class="md-nav__link">
        🌠 下载星巴克产品图片
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../demos/douban_book_pics/" class="md-nav__link">
        🌠 下载豆瓣图书封面图片
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../demos/multithreading_with_tabs/" class="md-nav__link">
        🌠 多线程操作多标签页
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="https://www.toutiao.com/article/7290179565996343847/" class="md-nav__link">
        🌠 巡检自动上报(网友投稿)
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../Q%26A/" class="md-nav__link">
        常见问题
      </a>
    </li>
  

    
      
      
      

  
  
  
    
    <li class="md-nav__item md-nav__item--nested">
      
      
      
      
      <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_7" >
      
      
      
        <label class="md-nav__link" for="__nav_7" id="__nav_7_label" tabindex="0">
          版本历史
          <span class="md-nav__icon md-icon"></span>
        </label>
      
      <nav class="md-nav" data-md-level="1" aria-labelledby="__nav_7_label" aria-expanded="false">
        <label class="md-nav__title" for="__nav_7">
          <span class="md-nav__icon md-icon"></span>
          版本历史
        </label>
        <ul class="md-nav__list" data-md-scrollfix>
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../history/introduction/" class="md-nav__link">
        自述
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../history/4.x/" class="md-nav__link">
        v4.x
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../history/3.x/" class="md-nav__link">
        v3.x
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../history/2.x/" class="md-nav__link">
        v1.5 - v2.x
      </a>
    </li>
  

            
          
            
              
  
  
  
    <li class="md-nav__item">
      <a href="../../history/1.x/" class="md-nav__link">
        v0.x - v1.4
      </a>
    </li>
  

            
          
        </ul>
      </nav>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="https://gitee.com/g1879/DrissionPage/issues" class="md-nav__link">
        意见建议
      </a>
    </li>
  

    
      
      
      

  
  
  
    <li class="md-nav__item">
      <a href="../../cooperation/" class="md-nav__link">
        商业合作
      </a>
    </li>
  

    
  </ul>
</nav>
                  </div>
                </div>
              </div>
            
            
              
              <div class="md-sidebar md-sidebar--secondary" data-md-component="sidebar" data-md-type="toc" >
                <div class="md-sidebar__scrollwrap">
                  <div class="md-sidebar__inner">
                    

<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
  
  
  
  
    <label class="md-nav__title" for="__toc">
      <span class="md-nav__icon md-icon"></span>
      Table of contents
    </label>
    <ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
      
        <li class="md-nav__item">
  <a href="#_1" class="md-nav__link">
    ✅️ 新的抓包功能
  </a>
  
    <nav class="md-nav" aria-label="✅️ 新的抓包功能">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#api" class="md-nav__link">
    📌 旧 api 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#api_1" class="md-nav__link">
    📌 新 api
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_2" class="md-nav__link">
    📌 示例
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_3" class="md-nav__link">
    ✅️ 新的页面访问逻辑
  </a>
  
    <nav class="md-nav" aria-label="✅️ 新的页面访问逻辑">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#api_2" class="md-nav__link">
    📌 api 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_4" class="md-nav__link">
    📌 行为变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#none" class="md-nav__link">
    📌 新的none加载模式
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_5" class="md-nav__link">
    📌 示例
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_6" class="md-nav__link">
    ✅️ 新的下载管理功能
  </a>
  
    <nav class="md-nav" aria-label="✅️ 新的下载管理功能">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#api_3" class="md-nav__link">
    📌 api 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_7" class="md-nav__link">
    📌 新增功能
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_8" class="md-nav__link">
    📌 行为变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_9" class="md-nav__link">
    📌 示例
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_10" class="md-nav__link">
    ✅️ 页面对象
  </a>
  
    <nav class="md-nav" aria-label="✅️ 页面对象">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_11" class="md-nav__link">
    📌 启动参数变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_12" class="md-nav__link">
    📌 内置动作链
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_13" class="md-nav__link">
    📌 状态信息
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_14" class="md-nav__link">
    📌 其它
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#cookies" class="md-nav__link">
    ✅️ cookies 设置
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_15" class="md-nav__link">
    ✅️ 标签页管理
  </a>
  
    <nav class="md-nav" aria-label="✅️ 标签页管理">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#to_tab" class="md-nav__link">
    📌 不再支持to_tab()功能
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#new_tab" class="md-nav__link">
    📌 new_tab()的新功能
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_16" class="md-nav__link">
    📌 标签页的位置与大小
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_17" class="md-nav__link">
    📌 标签页的行为
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#get_tab" class="md-nav__link">
    📌 get_tab()参数变化
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_18" class="md-nav__link">
    ✅️ 元素相关
  </a>
  
    <nav class="md-nav" aria-label="✅️ 元素相关">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#_19" class="md-nav__link">
    📌 定位语法变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_20" class="md-nav__link">
    📌 相对定位参数优化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_21" class="md-nav__link">
    📌 位置和大小
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_22" class="md-nav__link">
    📌 点击
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_23" class="md-nav__link">
    📌 查找元素失败显示细节
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_24" class="md-nav__link">
    📌 设置查找失败元素返回默认值
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_25" class="md-nav__link">
    📌 更多
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_26" class="md-nav__link">
    ✅️ 启动配置
  </a>
  
    <nav class="md-nav" aria-label="✅️ 启动配置">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#easy_set" class="md-nav__link">
    📌 删除 easy_set 方法
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_27" class="md-nav__link">
    📌 支持设置实验项
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#ini" class="md-nav__link">
    📌 ini 文件变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#chromiumoptions" class="md-nav__link">
    📌 ChromiumOptions 修改
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#sessionoptions" class="md-nav__link">
    📌 SessionOptions 修改
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_28" class="md-nav__link">
    📌 其它
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_29" class="md-nav__link">
    ✅️ 其它
  </a>
  
    <nav class="md-nav" aria-label="✅️ 其它">
      <ul class="md-nav__list">
        
          <li class="md-nav__item">
  <a href="#2x" class="md-nav__link">
    📌 删除 2.x 代码
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_30" class="md-nav__link">
    📌 异常变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#settings" class="md-nav__link">
    📌 Settings 变化
  </a>
  
</li>
        
          <li class="md-nav__item">
  <a href="#_31" class="md-nav__link">
    📌 更多
  </a>
  
</li>
        
      </ul>
    </nav>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_32" class="md-nav__link">
    ✅️ 问题修复
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_33" class="md-nav__link">
    ✅️ 下一步计划
  </a>
  
</li>
      
        <li class="md-nav__item">
  <a href="#_34" class="md-nav__link">
    ✅️ 加快开发进度
  </a>
  
</li>
      
    </ul>
  
</nav>
                  </div>
                </div>
              </div>
            
          
          
            <div class="md-content" data-md-component="content">
              <article class="md-content__inner md-typeset">
                
                  


  <h1>💥 4.0 功能介绍</h1>

<p>3.x 是自主研发底层的初步尝试，很多地方摸着石头过河，存在一些不太成熟的地方。</p>
<p>经过一段时间的使用，积累一些经验之后，4.0 在 3.x 的基础上对底层进行了大幅重构，新增大量功能，改善运行效率和稳定性，优化项目结构，解决很多存在的问题。对比旧版本有质的提高。</p>
<p>但同时不少 api 发生了变化，不能完全兼容旧版本。</p>
<p>api 的变化有些是功能优化必需的改变，有些则是本人对命名简洁的执念，趁着大版本的更新顺便把长期不太满意的命名给改了。</p>
<p>给使用者造成一定不便感到抱歉，但长痛不如短痛，趁着项目用的人不多，干脆舍弃历史包袱果断改掉。</p>
<p>有些原来的写法在 4.0.0 中还能正常使用，但 IDE 会提示无效，将在以后的版本中完全删除。推荐尽快更新为新写法。</p>
<p>本节仅简述功能变化，具体使用方法详见各对应章节。</p>
<h2 id="_1">✅️ 新的抓包功能</h2>
<p>3.2 中，抓包功能主要由 FlowViewer 和<code>wait.data_packets()</code>提供。</p>
<p>FlowViewer 是本人的一个练手作品，写得比较随意，技术也还没到家。存在漏抓、信息不全、api 不够合理的问题。</p>
<p>4.0 中，每个页面对象都内置了监听器，能力全面升级，api 也更合理。</p>
<h3 id="api">📌 旧 api 变化</h3>
<ul>
<li>弃用 FlowViewer，以后也不会再升级</li>
<li>删除<code>wait.set_targets()</code></li>
<li>删除<code>wait.stop_listening()</code>方法</li>
<li>删除<code>wait.data_packets()</code>方法</li>
<li><code>DrissionPage.common</code>路径删除<code>FlowViewer</code></li>
</ul>
<hr />
<h3 id="api_1">📌 新 api</h3>
<ul>
<li>每个标签页对象（包括<code>ChromiumFrame</code>）新增<code>listen</code>属性，内置监听功能</li>
<li>用<code>listen.set_start()</code>和<code>listen.stop()</code>启动和停止监听</li>
<li>用<code>listen.wait()</code>阻塞等待数据包</li>
<li>用<code>listen.steps()</code>同步获取监听结果</li>
<li>增加<code>listen.wait_silent()</code>等待所有请求完成（包含 target 以外的）</li>
<li>监听结果结构优化，request 和 response 数据分开存放</li>
</ul>
<hr />
<h3 id="_2">📌 示例</h3>
<p>下面示例可直接运行查看结果。这个示例会计时，用于与下个示例对比。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumPage</span>
<a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="kn">from</span> <span class="nn">TimePinner</span> <span class="kn">import</span> <span class="n">Pinner</span>
<a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="kn">from</span> <span class="nn">pprint</span> <span class="kn">import</span> <span class="n">pprint</span>
<a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a>
<a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="n">page</span> <span class="o">=</span> <span class="n">ChromiumPage</span><span class="p">()</span>
<a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a><span class="n">page</span><span class="o">.</span><span class="n">listen</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="s1">&#39;api/getkeydata&#39;</span><span class="p">)</span>  <span class="c1"># 指定监听目标并启动监听</span>
<a id="__codelineno-0-7" name="__codelineno-0-7" href="#__codelineno-0-7"></a><span class="n">pinner</span> <span class="o">=</span> <span class="n">Pinner</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<a id="__codelineno-0-8" name="__codelineno-0-8" href="#__codelineno-0-8"></a><span class="n">page</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http://www.hao123.com/&#39;</span><span class="p">)</span>  <span class="c1"># 访问网站</span>
<a id="__codelineno-0-9" name="__codelineno-0-9" href="#__codelineno-0-9"></a><span class="n">packet</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">listen</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>  <span class="c1"># 等待数据包</span>
<a id="__codelineno-0-10" name="__codelineno-0-10" href="#__codelineno-0-10"></a><span class="n">pprint</span><span class="p">(</span><span class="n">packet</span><span class="o">.</span><span class="n">response</span><span class="o">.</span><span class="n">body</span><span class="p">)</span>  <span class="c1"># 打印数据包正文</span>
<a id="__codelineno-0-11" name="__codelineno-0-11" href="#__codelineno-0-11"></a><span class="n">pinner</span><span class="o">.</span><span class="n">pin</span><span class="p">(</span><span class="s1">&#39;用时&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
</code></pre></div>
<p><strong>输出：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="o">{</span><span class="s1">&#39;hao123.new.shishi.bangdan.recom&#39;</span>:<span class="w"> </span><span class="o">[{</span><span class="s1">&#39;index&#39;</span>:<span class="w"> </span><span class="s1">&#39;1&#39;</span>,
<a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="w">                                      </span><span class="s1">&#39;pure_title&#39;</span>:<span class="w"> </span><span class="s1">&#39;以色列和哈马斯移交首批被扣押人员&#39;</span><span class="o">}</span>,
<a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="w">                                     </span><span class="o">{</span><span class="s1">&#39;index&#39;</span>:<span class="w"> </span><span class="s1">&#39;2&#39;</span>,
<a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="w">                                      </span><span class="s1">&#39;pure_title&#39;</span>:<span class="w"> </span><span class="s1">&#39;听到免签政策法国外长笑了&#39;</span><span class="o">}</span>,
<a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a><span class="w">                                     </span>......
<a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a>用时：3.3114853000151925
</code></pre></div>
<hr />
<h2 id="_3">✅️ 新的页面访问逻辑</h2>
<p>3.x 中存连接存在以下主要问题：</p>
<ul>
<li>浏览器页面对象<code>get()</code>方法的<code>timeout</code>参数只对加载阶段生效，无法覆盖连接阶段；</li>
<li>加载策略<code>none</code>模式没有实际用处。</li>
</ul>
<p>这两个问题都在 4.0 中解决，且能够让用户自主控制终止连接的时机。
另外还对连接逻辑进行了优化，避免卡死情况出现。</p>
<h3 id="api_2">📌 api 变化</h3>
<ul>
<li>页面对象<code>page_load_strategy</code>属性改名为<code>load_mode</code></li>
<li><code>set.load_strategy</code>改为<code>set.load_mode</code></li>
</ul>
<hr />
<h3 id="_4">📌 行为变化</h3>
<ul>
<li><code>get()</code>方法的<code>timeout</code>参数现在可覆盖整个过程</li>
<li><code>timeout</code>参数对非<code>get()</code>方法触发的加载（如点击链接）也能生效</li>
<li><code>SessionPage</code>和<code>WebPage</code>的 s 模式，如收到空数据，也会重试</li>
<li><code>SessionPage</code>的<code>get()</code>方法可以指向本地文件</li>
</ul>
<hr />
<h3 id="none">📌 新的<code>none</code>加载模式</h3>
<p>旧版中，<code>none</code>加载策略是当页面连接成功就立刻停止加载，这在实际使用时没有什么意义。</p>
<p>新版中，这个模式改成：除非加载完成，否则程序不会主动将其停止（即使已超时），同时连接状态不再阻塞程序，而允许用户进行状态判断，主动停止加载。</p>
<p>这样提供给用户非常大的自由度，可等到关键数据包或元素出现就主动停止页面加载，大幅提升执行效率。</p>
<hr />
<h3 id="_5">📌 示例</h3>
<p>我们继续使用上一个示例的代码，但把加载模式设为<code>none</code>，且获取到数据时主动停止加载。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-2-1" name="__codelineno-2-1" href="#__codelineno-2-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumPage</span>
<a id="__codelineno-2-2" name="__codelineno-2-2" href="#__codelineno-2-2"></a><span class="kn">from</span> <span class="nn">TimePinner</span> <span class="kn">import</span> <span class="n">Pinner</span>
<a id="__codelineno-2-3" name="__codelineno-2-3" href="#__codelineno-2-3"></a><span class="kn">from</span> <span class="nn">pprint</span> <span class="kn">import</span> <span class="n">pprint</span>
<a id="__codelineno-2-4" name="__codelineno-2-4" href="#__codelineno-2-4"></a>
<a id="__codelineno-2-5" name="__codelineno-2-5" href="#__codelineno-2-5"></a><span class="n">page</span> <span class="o">=</span> <span class="n">ChromiumPage</span><span class="p">()</span>
<a id="__codelineno-2-6" name="__codelineno-2-6" href="#__codelineno-2-6"></a><span class="n">page</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">load_mode</span><span class="o">.</span><span class="n">none</span><span class="p">()</span>  <span class="c1"># 设置加载模式为none</span>
<a id="__codelineno-2-7" name="__codelineno-2-7" href="#__codelineno-2-7"></a><span class="n">page</span><span class="o">.</span><span class="n">listen</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="s1">&#39;api/getkeydata&#39;</span><span class="p">)</span>  <span class="c1"># 指定监听目标并启动监听</span>
<a id="__codelineno-2-8" name="__codelineno-2-8" href="#__codelineno-2-8"></a><span class="n">pinner</span> <span class="o">=</span> <span class="n">Pinner</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
<a id="__codelineno-2-9" name="__codelineno-2-9" href="#__codelineno-2-9"></a><span class="n">page</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;http://www.hao123.com/&#39;</span><span class="p">)</span>  <span class="c1"># 访问网站</span>
<a id="__codelineno-2-10" name="__codelineno-2-10" href="#__codelineno-2-10"></a><span class="n">packet</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">listen</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>  <span class="c1"># 等待数据包</span>
<a id="__codelineno-2-11" name="__codelineno-2-11" href="#__codelineno-2-11"></a><span class="n">page</span><span class="o">.</span><span class="n">stop_loading</span><span class="p">()</span>  <span class="c1"># 主动停止加载</span>
<a id="__codelineno-2-12" name="__codelineno-2-12" href="#__codelineno-2-12"></a><span class="n">pprint</span><span class="p">(</span><span class="n">packet</span><span class="o">.</span><span class="n">response</span><span class="o">.</span><span class="n">body</span><span class="p">)</span>  <span class="c1"># 打印数据包正文</span>
<a id="__codelineno-2-13" name="__codelineno-2-13" href="#__codelineno-2-13"></a><span class="n">pinner</span><span class="o">.</span><span class="n">pin</span><span class="p">(</span><span class="s1">&#39;用时&#39;</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
</code></pre></div>
<p><strong>输出：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="o">{</span><span class="s1">&#39;hao123.new.shishi.bangdan.recom&#39;</span>:<span class="w"> </span><span class="o">[{</span><span class="s1">&#39;index&#39;</span>:<span class="w"> </span><span class="s1">&#39;1&#39;</span>,
<a id="__codelineno-3-2" name="__codelineno-3-2" href="#__codelineno-3-2"></a><span class="w">                                      </span><span class="s1">&#39;pure_title&#39;</span>:<span class="w"> </span><span class="s1">&#39;以色列和哈马斯移交首批被扣押人员&#39;</span><span class="o">}</span>,
<a id="__codelineno-3-3" name="__codelineno-3-3" href="#__codelineno-3-3"></a><span class="w">                                     </span><span class="o">{</span><span class="s1">&#39;index&#39;</span>:<span class="w"> </span><span class="s1">&#39;2&#39;</span>,
<a id="__codelineno-3-4" name="__codelineno-3-4" href="#__codelineno-3-4"></a><span class="w">                                      </span><span class="s1">&#39;pure_title&#39;</span>:<span class="w"> </span><span class="s1">&#39;听到免签政策法国外长笑了&#39;</span><span class="o">}</span>,
<a id="__codelineno-3-5" name="__codelineno-3-5" href="#__codelineno-3-5"></a><span class="w">                                     </span>......
<a id="__codelineno-3-6" name="__codelineno-3-6" href="#__codelineno-3-6"></a>用时：1.2575092000188306
</code></pre></div>
<p>可见节省了2秒时间。
当网站要访问一些不稳定资源时，节省的时间相当客观，也能提高程序的稳定性。</p>
<hr />
<h2 id="_6">✅️ 新的下载管理功能</h2>
<p>在旧版中，下载管理功能存在以下问题：</p>
<ul>
<li>浏览器下载管理和内置下载器<code>DownloadKit</code>的配置都使用<code>download_set</code>属性进行设置，容易造成混淆。</li>
<li>浏览器下载任务不能在下载前指定文件名</li>
<li>该功能有随着浏览器版本更新失效的风险</li>
</ul>
<p>4.0 对浏览器下载管理功能进行了完完全全的重构，结构更为合理，功能更多。
同时，内置下载器的设置和浏览器下载任务设置进行了分离。</p>
<h3 id="api_3">📌 api 变化</h3>
<ul>
<li>页面对象删除<code>download_set</code>属性</li>
<li>增加<code>set.download_path()</code>方法</li>
<li>增加<code>set.download_file_name()</code>方法</li>
</ul>
<hr />
<h3 id="_7">📌 新增功能</h3>
<ul>
<li>Tab 对象和 Frame 对象也支持<code>download()</code>方法</li>
<li>每个 Tab 对象可单独设置下载路径和重命名文件名</li>
<li>可拦截浏览器下载任务并获取其信息</li>
<li>可取消浏览器下载任务、获取下载进度、等待任务完成</li>
<li>可设置遇到文件夹已存在时的处理方式</li>
</ul>
<hr />
<h3 id="_8">📌 行为变化</h3>
<p>4.0 中默认不启用浏览器下载任务管理，只有在启动参数中设置了下载路径，或调用<code>set.download_path()</code>方法时才会启动。</p>
<p>未启动任务管理功能时，下载行为和普通使用一样。</p>
<hr />
<h3 id="_9">📌 示例</h3>
<p>以下示例可直接运行。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumPage</span>
<a id="__codelineno-4-2" name="__codelineno-4-2" href="#__codelineno-4-2"></a>
<a id="__codelineno-4-3" name="__codelineno-4-3" href="#__codelineno-4-3"></a><span class="n">page</span> <span class="o">=</span> <span class="n">ChromiumPage</span><span class="p">()</span>
<a id="__codelineno-4-4" name="__codelineno-4-4" href="#__codelineno-4-4"></a><span class="n">page</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://office.qq.com/download.html&#39;</span><span class="p">)</span>
<a id="__codelineno-4-5" name="__codelineno-4-5" href="#__codelineno-4-5"></a><span class="n">page</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">download_path</span><span class="p">(</span><span class="s1">&#39;tmp&#39;</span><span class="p">)</span>  <span class="c1"># 设置文件保存路径</span>
<a id="__codelineno-4-6" name="__codelineno-4-6" href="#__codelineno-4-6"></a><span class="n">page</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">download_file_name</span><span class="p">(</span><span class="s1">&#39;qq&#39;</span><span class="p">)</span>  <span class="c1"># 设置文件名</span>
<a id="__codelineno-4-7" name="__codelineno-4-7" href="#__codelineno-4-7"></a><span class="n">page</span><span class="p">(</span><span class="s1">&#39;#downloadWin&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">click</span><span class="p">()</span>  <span class="c1"># 点击触发下载</span>
<a id="__codelineno-4-8" name="__codelineno-4-8" href="#__codelineno-4-8"></a><span class="n">mission</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">wait</span><span class="o">.</span><span class="n">download_begin</span><span class="p">()</span>  <span class="c1"># 等待下载开始并获取任务对象</span>
<a id="__codelineno-4-9" name="__codelineno-4-9" href="#__codelineno-4-9"></a><span class="n">mission</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>  <span class="c1"># 等下下载任务完成</span>
</code></pre></div>
<p><strong>输出：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a>url：https://dldir1.qq.com/qqfile/qq/TIM3.4.8/TIM3.4.8.22124.exe
<a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a>文件名：qq.exe
<a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a>目标路径：D:<span class="se">\c</span>oding<span class="se">\p</span>rojects<span class="se">\D</span>rissionPage<span class="se">\t</span>mp
<a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="m">100</span>.0%<span class="w"> </span>下载完成<span class="w"> </span>D:<span class="se">\c</span>oding<span class="se">\p</span>rojects<span class="se">\D</span>rissionPage<span class="se">\t</span>mp<span class="se">\q</span>q.exe
</code></pre></div>
<hr />
<h2 id="_10">✅️ 页面对象</h2>
<p>这里说的页面对象包括 Page 对象（<code>ChromiumPage</code>、<code>WebPage</code>）、Tab 对象（<code>ChromiumTab</code>、<code>WebPageTab</code>）、<code>ChromiumFrame</code>对象。</p>
<h3 id="_11">📌 启动参数变化</h3>
<p>4.0 中，创建<code>WebPage</code>和<code>ChromiumPage</code>对象时，不再接收<code>ChromiumDriver</code>对象。</p>
<p>意思是不再支持传递控制权的方式创建页面对象。</p>
<p>因为本身支持多个页面对象控制同一个标签页，如果需要多页面对象协同，只要<code>get_tab()</code>创建一个新对象就行，可和原有对象并行使用。</p>
<p>而且，传递控制权本身有稳定性方面隐患，因此新版中将其删除。</p>
<p>相应地，启动参数的名称也发生了变化：</p>
<ul>
<li><code>WebPage</code>对象的<code>driver_or_options</code>参数改名为<code>chromium_options</code></li>
<li><code>ChromiumPage</code>对象的<code>addr_driver_opts</code>参数改名为<code>addr_or_opts</code></li>
</ul>
<p>另外，<code>ChromiumPage</code>的启动参数<code>addr_or_opts</code>现在可以接收<code>int</code>数据，直接传入端口号。</p>
<hr />
<h3 id="_12">📌 内置动作链</h3>
<p>4.0 中，每个页面对象内置<code>actions</code>属性，即动作链。</p>
<p>内置的动作链与直接创建的动作链对象有一个不同点，每次操作会等待页面加载完成再执行。</p>
<p><strong>示例：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="n">page</span><span class="o">.</span><span class="n">actions</span><span class="o">.</span><span class="n">hold</span><span class="p">(</span><span class="n">ele</span><span class="p">)</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span><span class="o">.</span><span class="n">release</span><span class="p">()</span>
</code></pre></div>
<hr />
<h3 id="_13">📌 状态信息</h3>
<p>旧版中，页面对象拥有<code>ready_state</code>、<code>is_loading</code>、<code>is_alive</code>属性，现在都合并到<code>states</code>属性中。</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="c1"># ------ 旧版代码 ------</span>
<a id="__codelineno-7-2" name="__codelineno-7-2" href="#__codelineno-7-2"></a><span class="nb">print</span><span class="p">(</span><span class="n">page</span><span class="o">.</span><span class="n">is_loading</span><span class="p">)</span>
<a id="__codelineno-7-3" name="__codelineno-7-3" href="#__codelineno-7-3"></a>
<a id="__codelineno-7-4" name="__codelineno-7-4" href="#__codelineno-7-4"></a><span class="c1"># ------ 新版代码 ------</span>
<a id="__codelineno-7-5" name="__codelineno-7-5" href="#__codelineno-7-5"></a><span class="nb">print</span><span class="p">(</span><span class="n">page</span><span class="o">.</span><span class="n">states</span><span class="o">.</span><span class="n">is_loading</span><span class="p">)</span>
</code></pre></div>
<hr />
<h3 id="_14">📌 其它</h3>
<ul>
<li>页面对象增加<code>raw_data</code>参数，s 模式下返回原始数据</li>
<li>所有页面对象增加<code>close()</code>方法，<code>SessionPage</code>用于关闭连接，浏览器页面对象用于关闭标签页</li>
<li>浏览器页面对象增加<code>wait()</code>方法，用于等待若干秒</li>
<li>浏览器页面对象增加<code>wait.ele_loaded()</code>方法，等待元素加载到DOM</li>
<li>浏览器页面对象增加<code>wait.title_change()</code>和<code>wait.url_change()</code>方法，用于等待 title 和 url 变化</li>
<li>浏览器页面对象增加<code>wait.alert_closed()</code>方法，用于等待弹窗被手动关闭</li>
<li>浏览器页面对象增加<code>set.cookie()</code>方法，可设置单个 cookie</li>
<li>浏览器页面对象增加<code>set.blocked_urls()</code>方法，可设置忽略的连接</li>
<li>Tab 和 Page 对象增加<code>disconnect()</code>方法，用于断开与网页连接</li>
<li>Tab 和 Page 对象增加<code>save()</code>方法，用于把网页保存为 mhtml</li>
<li>Tab 和 Page 对象增加<code>add_init_js()</code>和<code>remove_init_js()</code>方法</li>
<li><code>quit()</code>方法增加<code>force</code>参数，可强制关闭浏览器进程</li>
<li><code>ChromiumFrame</code>增加<code>ract</code>属性</li>
<li><code>ChromiumFrame</code>的<code>frame_size</code>属性改为<code>rect.size</code></li>
<li><code>wait.ele_delete()</code>方法改为<code>wait.ele_deleted()</code></li>
<li><code>wait.ele_display()</code>方法改为<code>wait.ele_displayed()</code></li>
<li>优化<code>SessionPage</code>和<code>WebPage</code>s 模式访问速度</li>
<li><code>WebPage</code>在 d 模式时，<code>post()</code>返回<code>Response</code>对象</li>
<li><code>get_frame()</code>方法按序号获取时改成从<code>0</code>开始计算</li>
</ul>
<hr />
<h2 id="cookies">✅️ cookies 设置</h2>
<ul>
<li><code>set.cookies()</code>可接收单个 cookie</li>
<li>增加<code>set.cookies.clear()</code>方法用于清除 cookies</li>
<li>增加<code>set.cookies.remove()</code>方法用于删除一个 cookie 项</li>
</ul>
<hr />
<h2 id="_15">✅️ 标签页管理</h2>
<h3 id="to_tab">📌 不再支持<code>to_tab()</code>功能</h3>
<p><code>to_tab()</code>的设计源自于 selenium，用于在多个标签页间切换程序焦点。</p>
<p>selenium 没有 tab 对象，driver 每次只能操作一个 tab。多 tab 使用时需在不同的 tab 间来回切换，且切换的时候会丢失之前获取过的元素，效率低，使用不便。</p>
<p>DrissionPage 3.x 开始就支持多 tab 对象共存，对象之间互不影响，而且标签页无需激活即可操作。因此不再需要切换标签页。</p>
<p>而且焦点切换时如果页面正在加载，实现逻辑较为复杂，也会有稳定性问题。</p>
<p>基于此，决定删除<code>to_tab()</code>方法，使用<code>get_tab()</code>取代之。</p>
<p><strong>涉及的 api修改：</strong></p>
<ul>
<li>删除<code>to_tab()</code>方法</li>
<li>删除<code>to_main_tab()</code>、<code>set.main_tab()</code>方法</li>
<li>删除<code>main_tab</code>属性</li>
<li><code>new_tab()</code>方法删除<code>switch_to</code>参数</li>
</ul>
<p><strong>新建标签页并切换到新标签页：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-8-1" name="__codelineno-8-1" href="#__codelineno-8-1"></a><span class="c1"># ------ 旧版代码 ------</span>
<a id="__codelineno-8-2" name="__codelineno-8-2" href="#__codelineno-8-2"></a><span class="n">tab</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">new_tab</span><span class="p">(</span><span class="n">switch_to</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<a id="__codelineno-8-3" name="__codelineno-8-3" href="#__codelineno-8-3"></a>
<a id="__codelineno-8-4" name="__codelineno-8-4" href="#__codelineno-8-4"></a><span class="c1"># ------ 新版代码 ------</span>
<a id="__codelineno-8-5" name="__codelineno-8-5" href="#__codelineno-8-5"></a><span class="n">tab</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">new_tab</span><span class="p">()</span>
</code></pre></div>
<p><strong>操作另一个标签页</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a><span class="c1"># ------ 旧版代码 ------</span>
<a id="__codelineno-9-2" name="__codelineno-9-2" href="#__codelineno-9-2"></a><span class="n">page</span><span class="o">.</span><span class="n">to_tab</span><span class="p">(</span><span class="n">page</span><span class="o">.</span><span class="n">tabs</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<a id="__codelineno-9-3" name="__codelineno-9-3" href="#__codelineno-9-3"></a>
<a id="__codelineno-9-4" name="__codelineno-9-4" href="#__codelineno-9-4"></a><span class="c1"># ------ 新版代码 ------</span>
<a id="__codelineno-9-5" name="__codelineno-9-5" href="#__codelineno-9-5"></a><span class="n">tab</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">get_tab</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># 创建一个可与page同时使用的tab对象</span>
</code></pre></div>
<hr />
<h3 id="new_tab">📌 <code>new_tab()</code>的新功能</h3>
<p>Page 对象的<code>new_tab()</code>方法增加了 3 个参数：</p>
<ul>
<li><code>new_window</code>：是否创建新的窗口，新窗口与旧标签页同属一个浏览器，只是独立窗口</li>
<li><code>background</code>：新建的标签页是否为不激活状态（即使不激活也可以操作）</li>
<li><code>new_context</code>：是否创建独立的隐身窗口，该窗口与旧标签页 cookies 相互独立</li>
</ul>
<p>现在<code>new_tab()</code>返回新建的标签页对象，而非其 tab_id。</p>
<p><strong>示例：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="n">tab</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">new_tab</span><span class="p">()</span>
<a id="__codelineno-10-2" name="__codelineno-10-2" href="#__codelineno-10-2"></a><span class="n">tab</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://g1879.gitee.io/drissionpagedocs&#39;</span><span class="p">)</span>
</code></pre></div>
<hr />
<h3 id="_16">📌 标签页的位置与大小</h3>
<p>在旧版中，只有<code>ChromiumPage</code>或<code>WebPage</code>对象可以设置窗口位置、大小、状态。</p>
<p>Tab 对象（<code>ChromiumTan</code>、<code>WebPageTab</code>）虽然能获取窗口窗口上述信息，但只是获取 Page 所控制的标签页信息。</p>
<p>在 4.0 中，独立窗口的标签页，也能设置和获取上面这些属性。</p>
<p>以下属性和方法名称进行了修改:</p>
<ul>
<li><code>rect.borwser_size</code>改为<code>rect.window_size</code></li>
<li><code>rect.borwser_location</code>改为<code>rect.window_location</code></li>
<li><code>set.window.maximized()</code>改为<code>set.window.max()</code></li>
<li><code>set.window.minimized()</code>改为<code>set.window.mini()</code></li>
<li><code>set.window.fullscreen()</code>改为<code>set.window.full()</code></li>
</ul>
<p><strong>示例：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a><span class="n">tab</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">get_tab</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<a id="__codelineno-11-2" name="__codelineno-11-2" href="#__codelineno-11-2"></a><span class="nb">print</span><span class="p">(</span><span class="n">tab</span><span class="o">.</span><span class="n">rect</span><span class="o">.</span><span class="n">window_state</span><span class="p">)</span>  <span class="c1"># 获取窗口状态</span>
<a id="__codelineno-11-3" name="__codelineno-11-3" href="#__codelineno-11-3"></a><span class="nb">print</span><span class="p">(</span><span class="n">tab</span><span class="o">.</span><span class="n">rect</span><span class="o">.</span><span class="n">window_location</span><span class="p">)</span>  <span class="c1"># 获取窗口位置</span>
<a id="__codelineno-11-4" name="__codelineno-11-4" href="#__codelineno-11-4"></a><span class="nb">print</span><span class="p">(</span><span class="n">tab</span><span class="o">.</span><span class="n">rect</span><span class="o">.</span><span class="n">window_size</span><span class="p">)</span>  <span class="c1"># 获取窗口大小</span>
<a id="__codelineno-11-5" name="__codelineno-11-5" href="#__codelineno-11-5"></a>
<a id="__codelineno-11-6" name="__codelineno-11-6" href="#__codelineno-11-6"></a><span class="n">tab</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">window</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="mi">500</span><span class="p">,</span> <span class="mi">500</span><span class="p">)</span>  <span class="c1"># 设置窗口大小</span>
<a id="__codelineno-11-7" name="__codelineno-11-7" href="#__codelineno-11-7"></a><span class="n">tab</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">window</span><span class="o">.</span><span class="n">location</span><span class="p">(</span><span class="mi">500</span><span class="p">,</span> <span class="mi">500</span><span class="p">)</span>  <span class="c1"># 设置窗口位置</span>
<a id="__codelineno-11-8" name="__codelineno-11-8" href="#__codelineno-11-8"></a><span class="n">tab</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">window</span><span class="o">.</span><span class="n">max</span><span class="p">()</span>  <span class="c1"># 窗口最大化</span>
<a id="__codelineno-11-9" name="__codelineno-11-9" href="#__codelineno-11-9"></a><span class="c1"># 更多详见相关文档……</span>
</code></pre></div>
<hr />
<h3 id="_17">📌 标签页的行为</h3>
<p>在旧版中，标签页的开关、激活由 Page 对象管理。JS 弹窗也只有 Page 对象能处理。</p>
<p>在 4.0 中，标签页对象可以激活、关闭自己，也可以处理自己的弹出对话框。</p>
<ul>
<li><code>tab.set.activate()</code>：标签页对象激活自己</li>
<li><code>tab.close()</code>：标签页对象关闭自己</li>
<li><code>tab.handle_alert()</code>：标签页对象处理自己的弹窗</li>
<li><code>tab.states.has_alert</code>：标签页增加此属性表示是否有弹窗存在</li>
</ul>
<hr />
<h3 id="get_tab">📌 <code>get_tab()</code>参数变化</h3>
<p>现在<code>get_tab()</code>方法可接收标签页序号（序号从 0 开始）。<code>tab_id</code>参数改为<code>id_or_num</code>。</p>
<p>但需要注意，序号与标签页视觉排序不一定一致，而是按照激活顺序排列。</p>
<p><strong>示例：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="n">tab</span> <span class="o">=</span> <span class="n">page</span><span class="o">.</span><span class="n">get_tab</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>  <span class="c1"># 获取列表中第二个标签页的对象</span>
</code></pre></div>
<hr />
<h2 id="_18">✅️ 元素相关</h2>
<h3 id="_19">📌 定位语法变化</h3>
<p>旧版中，定位语法中使用<code>@@-</code>或<code>@|-</code>表示否定，但视觉效果不明显，意义也不太明确。</p>
<p>因此改用<code>@!</code>替代，使其更能体现否定的含义。</p>
<p><code>@!</code>可与<code>@@</code>或<code>@|</code>混用，与还是或关系视<code>@@</code>还是<code>@|</code>而定。</p>
<p>也可以单独使用，否定某个单独属性。</p>
<p><strong>示例：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a><span class="c1"># ------ 旧版语法 ------</span>
<a id="__codelineno-13-2" name="__codelineno-13-2" href="#__codelineno-13-2"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;@@arg1=abc@@-arg2=def&#39;</span><span class="p">)</span>
<a id="__codelineno-13-3" name="__codelineno-13-3" href="#__codelineno-13-3"></a><span class="c1"># ------ 新版语法 ------</span>
<a id="__codelineno-13-4" name="__codelineno-13-4" href="#__codelineno-13-4"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;@@arg1=abc@!arg2=def&#39;</span><span class="p">)</span>
<a id="__codelineno-13-5" name="__codelineno-13-5" href="#__codelineno-13-5"></a>
<a id="__codelineno-13-6" name="__codelineno-13-6" href="#__codelineno-13-6"></a><span class="c1"># ------ 旧版语法 ------</span>
<a id="__codelineno-13-7" name="__codelineno-13-7" href="#__codelineno-13-7"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;t:div@|arg1=abc@|-arg2=def&#39;</span><span class="p">)</span>
<a id="__codelineno-13-8" name="__codelineno-13-8" href="#__codelineno-13-8"></a><span class="c1"># ------ 新版语法 ------</span>
<a id="__codelineno-13-9" name="__codelineno-13-9" href="#__codelineno-13-9"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;t:div@|arg1=abc@!arg2=def&#39;</span><span class="p">)</span>
<a id="__codelineno-13-10" name="__codelineno-13-10" href="#__codelineno-13-10"></a>
<a id="__codelineno-13-11" name="__codelineno-13-11" href="#__codelineno-13-11"></a><span class="c1"># ------ 旧版语法 ------</span>
<a id="__codelineno-13-12" name="__codelineno-13-12" href="#__codelineno-13-12"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;@@-arg1=abc&#39;</span><span class="p">)</span>
<a id="__codelineno-13-13" name="__codelineno-13-13" href="#__codelineno-13-13"></a><span class="c1"># ------ 新版语法 ------</span>
<a id="__codelineno-13-14" name="__codelineno-13-14" href="#__codelineno-13-14"></a><span class="n">page</span><span class="o">.</span><span class="n">ele</span><span class="p">(</span><span class="s1">&#39;@!arg1=abc&#39;</span><span class="p">)</span>
</code></pre></div>
<hr />
<h3 id="_20">📌 相对定位参数优化</h3>
<p>旧版本中，相对定位如果想用序号获取元素，需要写成<code>ele.next(index=1)</code>。</p>
<p>但是我想把这个语句变得更简化一点，写成<code>ele.next(1)</code>即可表示获取下一个兄弟元素。</p>
<p>4.0 中支持这种写法，当<code>filter_loc</code>参数接收<code>int</code>类型参数，即可当作<code>index</code>参数使用。</p>
<p><code>parent()</code>方法增加<code>index</code>参数，当<code>level_or_loc</code>传入定位符，使用此参数选择第几个结果。</p>
<hr />
<h3 id="_21">📌 位置和大小</h3>
<p>旧版中，元素大小和位置信息由<code>location</code>、<code>locations</code>、<code>size</code>几个属性提供。</p>
<p>这些属性都与形状相关，为使逻辑更清晰，与页面对象逻辑一致，将它们统一归纳到<code>rect</code>属性中。</p>
<ul>
<li>删除<code>size</code>、<code>location</code>、<code>locations</code>属性，新增<code>rect</code>属性</li>
<li>旧版中<code>loactions.xxxx</code>的属性改为<code>rect.xxxx</code></li>
<li>大小和位置信息，从<code>int</code>类型改为<code>float</code>类型</li>
<li>增加<code>states.has_rect</code>属性，返回元素是否拥有大小和位置</li>
<li>增加<code>states.is_whole_in_viewport</code>属性，返回元素是否整个都在视口内</li>
</ul>
<div class="highlight"><pre><span></span><code><a id="__codelineno-14-1" name="__codelineno-14-1" href="#__codelineno-14-1"></a><span class="c1"># ------ 旧版代码 ------</span>
<a id="__codelineno-14-2" name="__codelineno-14-2" href="#__codelineno-14-2"></a><span class="n">ele</span><span class="o">.</span><span class="n">size</span>
<a id="__codelineno-14-3" name="__codelineno-14-3" href="#__codelineno-14-3"></a><span class="n">ele</span><span class="o">.</span><span class="n">location</span>
<a id="__codelineno-14-4" name="__codelineno-14-4" href="#__codelineno-14-4"></a><span class="n">ele</span><span class="o">.</span><span class="n">locations</span><span class="o">.</span><span class="n">midpoint</span>
<a id="__codelineno-14-5" name="__codelineno-14-5" href="#__codelineno-14-5"></a>
<a id="__codelineno-14-6" name="__codelineno-14-6" href="#__codelineno-14-6"></a><span class="c1"># ------ 新版代码 ------</span>
<a id="__codelineno-14-7" name="__codelineno-14-7" href="#__codelineno-14-7"></a><span class="n">ele</span><span class="o">.</span><span class="n">rect</span><span class="o">.</span><span class="n">size</span>
<a id="__codelineno-14-8" name="__codelineno-14-8" href="#__codelineno-14-8"></a><span class="n">ele</span><span class="o">.</span><span class="n">rect</span><span class="o">.</span><span class="n">location</span>
<a id="__codelineno-14-9" name="__codelineno-14-9" href="#__codelineno-14-9"></a><span class="n">ele</span><span class="o">.</span><span class="n">rect</span><span class="o">.</span><span class="n">midpoint</span>
</code></pre></div>
<hr />
<h3 id="_22">📌 点击</h3>
<ul>
<li><code>click()</code>增加<code>wait_stop</code>参数，默认等待元素运动停止再点击</li>
<li><code>click()</code>默认等待元素运动停止再执行点击</li>
<li><code>click.twice()</code>改为<code>click.multiple()</code></li>
</ul>
<hr />
<h3 id="_23">📌 查找元素失败显示细节</h3>
<p>旧版链式查找元素时，遇到其中一个查找失败，不能很直观地显示哪个语句失败。</p>
<p>在 4.0 中，可以把查找失败的语句和定位语句显示在报错信息中。</p>
<p><strong>示例</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-15-1" name="__codelineno-15-1" href="#__codelineno-15-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumPage</span>
<a id="__codelineno-15-2" name="__codelineno-15-2" href="#__codelineno-15-2"></a>
<a id="__codelineno-15-3" name="__codelineno-15-3" href="#__codelineno-15-3"></a><span class="n">page</span> <span class="o">=</span> <span class="n">ChromiumPage</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<a id="__codelineno-15-4" name="__codelineno-15-4" href="#__codelineno-15-4"></a><span class="n">page</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;https://baidu.com&#39;</span><span class="p">)</span>
<a id="__codelineno-15-5" name="__codelineno-15-5" href="#__codelineno-15-5"></a><span class="nb">print</span><span class="p">(</span><span class="n">page</span><span class="p">(</span><span class="s1">&#39;#wrapper&#39;</span><span class="p">)(</span><span class="s1">&#39;#s_tab&#39;</span><span class="p">)(</span><span class="s1">&#39;#abcd&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>  <span class="c1"># (&#39;#abcd&#39;)这个元素不存在</span>
</code></pre></div>
<p>输出：</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-16-1" name="__codelineno-16-1" href="#__codelineno-16-1"></a>DrissionPage.errors.ElementNotFoundError:<span class="w"> </span>
<a id="__codelineno-16-2" name="__codelineno-16-2" href="#__codelineno-16-2"></a>没有找到元素。
<a id="__codelineno-16-3" name="__codelineno-16-3" href="#__codelineno-16-3"></a>method:<span class="w"> </span>ele<span class="o">()</span>
<a id="__codelineno-16-4" name="__codelineno-16-4" href="#__codelineno-16-4"></a>args:<span class="w"> </span><span class="o">{</span><span class="s1">&#39;loc_or_str&#39;</span>:<span class="w"> </span><span class="s1">&#39;#abcd&#39;</span><span class="o">}</span>
</code></pre></div>
<hr />
<h3 id="_24">📌 设置查找失败元素返回默认值</h3>
<p>如果查找元素后要获取一个属性，但这个元素不一定存在，或者链式查找其中一个节点找不到，可以设置查找失败时返回的值，而不是抛出异常。</p>
<p>这样可以简化一些采集逻辑。</p>
<p><strong>示例</strong></p>
<p>比如说，遍历页面上一个列表中多个对象，但其中有些元素可能确实某个子元素，旧版中要这样写：</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-17-1" name="__codelineno-17-1" href="#__codelineno-17-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumPage</span>
<a id="__codelineno-17-2" name="__codelineno-17-2" href="#__codelineno-17-2"></a>
<a id="__codelineno-17-3" name="__codelineno-17-3" href="#__codelineno-17-3"></a><span class="n">page</span> <span class="o">=</span> <span class="n">ChromiumPage</span><span class="p">()</span>
<a id="__codelineno-17-4" name="__codelineno-17-4" href="#__codelineno-17-4"></a><span class="k">for</span> <span class="n">li</span> <span class="ow">in</span> <span class="n">page</span><span class="o">.</span><span class="n">eles</span><span class="p">(</span><span class="s1">&#39;t:li&#39;</span><span class="p">):</span>
<a id="__codelineno-17-5" name="__codelineno-17-5" href="#__codelineno-17-5"></a>    <span class="n">ele</span> <span class="o">=</span> <span class="n">li</span><span class="p">(</span><span class="s1">&#39;.name&#39;</span><span class="p">)</span>
<a id="__codelineno-17-6" name="__codelineno-17-6" href="#__codelineno-17-6"></a>    <span class="n">name</span> <span class="o">=</span> <span class="n">ele</span><span class="o">.</span><span class="n">text</span> <span class="k">if</span> <span class="n">ele</span> <span class="k">else</span> <span class="kc">None</span>
<a id="__codelineno-17-7" name="__codelineno-17-7" href="#__codelineno-17-7"></a>    <span class="n">ele</span> <span class="o">=</span> <span class="n">li</span><span class="p">(</span><span class="s1">&#39;.age&#39;</span><span class="p">)</span>
<a id="__codelineno-17-8" name="__codelineno-17-8" href="#__codelineno-17-8"></a>    <span class="n">age</span> <span class="o">=</span> <span class="n">ele</span><span class="o">.</span><span class="n">text</span> <span class="k">if</span> <span class="n">ele</span> <span class="k">else</span> <span class="kc">None</span>
<a id="__codelineno-17-9" name="__codelineno-17-9" href="#__codelineno-17-9"></a>    <span class="n">ele</span> <span class="o">=</span> <span class="n">li</span><span class="p">(</span><span class="s1">&#39;.phone&#39;</span><span class="p">)</span>
<a id="__codelineno-17-10" name="__codelineno-17-10" href="#__codelineno-17-10"></a>    <span class="n">phone</span> <span class="o">=</span> <span class="n">ele</span><span class="o">.</span><span class="n">text</span> <span class="k">if</span> <span class="n">ele</span> <span class="k">else</span> <span class="kc">None</span>
</code></pre></div>
<p>在新版中，可以这样写：</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-18-1" name="__codelineno-18-1" href="#__codelineno-18-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumPage</span>
<a id="__codelineno-18-2" name="__codelineno-18-2" href="#__codelineno-18-2"></a>
<a id="__codelineno-18-3" name="__codelineno-18-3" href="#__codelineno-18-3"></a><span class="n">page</span> <span class="o">=</span> <span class="n">ChromiumPage</span><span class="p">()</span>
<a id="__codelineno-18-4" name="__codelineno-18-4" href="#__codelineno-18-4"></a><span class="n">page</span><span class="o">.</span><span class="n">set</span><span class="o">.</span><span class="n">NoneElement_value</span><span class="p">(</span><span class="s1">&#39;没找到&#39;</span><span class="p">)</span>
<a id="__codelineno-18-5" name="__codelineno-18-5" href="#__codelineno-18-5"></a><span class="k">for</span> <span class="n">li</span> <span class="ow">in</span> <span class="n">page</span><span class="o">.</span><span class="n">eles</span><span class="p">(</span><span class="s1">&#39;t:li&#39;</span><span class="p">):</span>
<a id="__codelineno-18-6" name="__codelineno-18-6" href="#__codelineno-18-6"></a>    <span class="n">name</span> <span class="o">=</span> <span class="n">li</span><span class="p">(</span><span class="s1">&#39;.name&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">text</span>
<a id="__codelineno-18-7" name="__codelineno-18-7" href="#__codelineno-18-7"></a>    <span class="n">age</span> <span class="o">=</span> <span class="n">li</span><span class="p">(</span><span class="s1">&#39;.age&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">text</span>
<a id="__codelineno-18-8" name="__codelineno-18-8" href="#__codelineno-18-8"></a>    <span class="n">phone</span> <span class="o">=</span> <span class="n">li</span><span class="p">(</span><span class="s1">&#39;.phone&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">text</span>
</code></pre></div>
<p>这样，假如某个子元素不存在，不会抛出异常，而是返回<code>'没找到'</code>这个字符串。</p>
<hr />
<h3 id="_25">📌 更多</h3>
<ul>
<li>增加<code>wait.stop_moving()</code>方法，可等待移动结束</li>
<li>增加<code>wait()</code>方法，用于等待若干秒</li>
<li>增加<code>check()</code>方法，可选中或取消选中元素</li>
<li>增加<code>wait.has_rect()</code>方法，用于等待元素拥有大小和位置</li>
<li>滚动添加<code>to_center()</code>方式，可滚动到视口中央</li>
<li>增加<code>select.by_option()</code>和<code>select.cancel_by_option()</code>方法，可选取列表项元素</li>
<li>增加<code>states.has_rect</code>属性</li>
<li>元素被覆盖时，<code>states.is_covered</code>属性返回覆盖元素的 id</li>
<li>添加<code>states.is_whole_in_viewport</code>属性，判断是否整个都在视口中</li>
<li><code>input()</code>方法增加<code>by_js</code>参数</li>
<li><code>save()</code>的<code>rename</code>参数改为<code>name</code></li>
<li><code>get_src()</code>支持 blob 类型</li>
<li><code>css_path</code>获取的路径更精确</li>
<li>相对定位的<code>timeout</code>参数默认改为<code>None</code></li>
<li><code>wait.delete()</code>方法改为<code>wait.deleted()</code></li>
<li><code>wait.disabled_or_delete()</code>方法改为<code>wait.disabled_or_deleted()</code></li>
<li><code>wait.display()</code>方法改为<code>wait.displayed()</code></li>
<li>可用<code>==</code>比较两个元素</li>
</ul>
<hr />
<h2 id="_26">✅️ 启动配置</h2>
<h3 id="easy_set">📌 删除 easy_set 方法</h3>
<p>easy_set 原本设计目的是为了方便修改 ini 文件设置。</p>
<p>本想着设置一次，之后无需再调用。但可能由于文档描述不清晰，很多人将其写到了正式的代码中。</p>
<p>因为 ini 文件的修改会影响其它项目，这是作者不推荐的用法。</p>
<p>而且，实际使用中发现 easy_set 并没有变得更方便，功能可用<code>ChromiumOptions</code>对象的<code>save()</code>方法代替。</p>
<p>因此决定将其删除，也可以免去多维护一份代码。</p>
<hr />
<h3 id="_27">📌 支持设置实验项</h3>
<p>4.0 新增支持启动浏览器时设置实验项，即<code>'chrome://flags'</code>中的项目。</p>
<p>使用新增的<code>set_flag()</code>方法设置。使用<code>clear_flags_in_file()</code>清空配置文件中已设置的项。</p>
<p>有哪些实验项，具体在<code>'chrome://flags'</code>查看。</p>
<p><strong>示例：</strong></p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-19-1" name="__codelineno-19-1" href="#__codelineno-19-1"></a><span class="kn">from</span> <span class="nn">DrissionPage</span> <span class="kn">import</span> <span class="n">ChromiumOptions</span>
<a id="__codelineno-19-2" name="__codelineno-19-2" href="#__codelineno-19-2"></a>
<a id="__codelineno-19-3" name="__codelineno-19-3" href="#__codelineno-19-3"></a><span class="n">co</span> <span class="o">=</span> <span class="n">ChromiumOptions</span><span class="p">()</span>
<a id="__codelineno-19-4" name="__codelineno-19-4" href="#__codelineno-19-4"></a><span class="n">co</span><span class="o">.</span><span class="n">set_flag</span><span class="p">(</span><span class="s1">&#39;temporary-unexpire-flags-m118&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">)</span>
<a id="__codelineno-19-5" name="__codelineno-19-5" href="#__codelineno-19-5"></a><span class="n">co</span><span class="o">.</span><span class="n">set_flag</span><span class="p">(</span><span class="s1">&#39;disable-accelerated-2d-canvas&#39;</span><span class="p">)</span> 
</code></pre></div>
<hr />
<h3 id="ini">📌 ini 文件变化</h3>
<ul>
<li><code>chrome_options</code>类改为<code>chromium_options</code></li>
<li><code>binary_location</code>项改为<code>browser_path</code></li>
<li><code>page_load_strategy</code>项改为<code>load_mode</code></li>
<li><code>debugger_address</code>项改为<code>address</code></li>
<li><code>arguments</code>项删除<code>'--remote-allow-origins=*'</code>参数</li>
<li><code>arguments</code>项增加<code>'--no-default-browser-check'</code>、<code>'--disable-suggestions-ui'</code>参数</li>
<li><code>paths</code>类增加<code>tmp_paht</code>项</li>
<li>删除<code>experimental_options</code>项</li>
<li><code>chrome_options</code>类增加<code>prefs</code>、<code>flags</code>、<code>existing_only</code>项</li>
<li>增加<code>others</code>类，包含<code>retry_times</code>和<code>retry_interval</code>项</li>
</ul>
<hr />
<h3 id="chromiumoptions">📌 <code>ChromiumOptions</code> 修改</h3>
<ul>
<li>增加<code>set_flag()</code>和<code>clear_flags_in_file()</code>，用于设置实验项</li>
<li>增加<code>existing_only()</code>方法和<code>is_existing_only</code>属性，可指定只接管浏览器而不自动启动新的</li>
<li>增加<code>ignore_certificate_errors()</code>方法，可忽略证书报错</li>
<li>增加<code>retry_times</code>、<code>retry_interval</code>属性和<code>set_retry()</code>方法，可设置重试参数</li>
<li>增加<code>incognito()</code>方法，可设置无痕模式</li>
<li>增加<code>set_tmp_path()</code>方法，可指定临时文件夹路径</li>
<li>增加<code>tmp_path</code>和<code>is_auto_port</code>属性</li>
<li><code>auto_port()</code>增加<code>tmp_path</code>参数</li>
<li><code>set_paths()</code>
  方法拆分成<code>set_browser_path()</code>、<code>set_local_port()</code>、<code>set_address()</code>、<code>set_download_path()</code>、<code>set_user_data_path()</code>、<code>set_cache_path()</code>
  方法</li>
<li><code>set_page_load_strategy()</code>改成<code>set_load_mode()</code></li>
<li><code>set_headless()</code>改成<code>headless()</code></li>
<li><code>set_no_imgs()</code>改成<code>no_imgs()</code></li>
<li><code>set_no_js()</code>改成<code>no_js()</code></li>
<li><code>set_mute()</code>改成<code>mute()</code></li>
<li><code>debugger_address</code>改成<code>address</code></li>
</ul>
<h3 id="sessionoptions">📌 <code>SessionOptions</code> 修改</h3>
<ul>
<li><code>SessionOptions</code>的<code>set_paths()</code>方法改为<code>set_download_path()</code></li>
<li>增加<code>retry_times</code>、<code>retry_interval</code>属性和<code>set_retry()</code>方法，可设置重试参数</li>
</ul>
<hr />
<h3 id="_28">📌 其它</h3>
<ul>
<li>启动或接管浏览器时，可自动关闭弹出的隐私声明</li>
<li>在无界面系统启动浏览器时，自动使用无头，可用<code>set_headless(False)</code>禁用</li>
<li>当<code>set_headless(False)</code>但接管了无头浏览器，将关闭并启动新的有头浏览器</li>
<li><code>auto_port()</code>方法支持多线程</li>
</ul>
<hr />
<h2 id="_29">✅️ 其它</h2>
<h3 id="2x">📌 删除 2.x 代码</h3>
<p><code>MixPage</code> 是 <code>WebPage</code>的前身，基于 selenium。</p>
<p>随着 3.x 版本迭代，自研的底层日渐成熟并完全超越旧版。旧版已到了退休的时候。。</p>
<p>为对项目进行精简，避免新代码受旧功能制约，因此将旧代码删除。</p>
<p>删除以下类：<code>MixPage</code>、<code>DriverPage</code>、<code>DriverOptions</code>、<code>Drission</code>。</p>
<p>旧版对作者的成长有过巨大贡献，因此将其独立成一个库，以此来继续它的生命，和纪念它做出过的成果。</p>
<p>可用以下命令安装旧版尝旧：</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-20-1" name="__codelineno-20-1" href="#__codelineno-20-1"></a>pip<span class="w"> </span>install<span class="w"> </span>MixPage
</code></pre></div>
<hr />
<h3 id="_30">📌 异常变化</h3>
<ul>
<li><code>CallMethodError</code>改为<code>CDPError</code></li>
<li><code>ElementLossError</code>改为<code>ElementLostError</code></li>
<li><code>ContextLossError</code>改为<code>ContextLostError</code></li>
<li><code>TabClosedError</code>改为<code>PageDisconnectedError</code></li>
<li>增加<code>WaitTimeoutError</code></li>
<li>增加<code>GetDocumentError</code></li>
<li>增加<code>WrongURLError</code></li>
<li>增加<code>StorageError</code></li>
<li>增加<code>CookieFormatError</code></li>
</ul>
<hr />
<h3 id="settings">📌 Settings 变化</h3>
<ul>
<li><code>raise_ele_not_found</code>改为<code>raise_when_ele_not_found</code></li>
<li><code>raise_click_failed</code>改为<code>raise_when_click_failed</code></li>
</ul>
<hr />
<h3 id="_31">📌 更多</h3>
<ul>
<li><code>handle_alert()</code>方法增加<code>next_one</code>参数，可处理下一个出现的弹窗</li>
<li>浏览器页面对象增加<code>set.auto_handle_alert()</code>方法，可设置自动处理弹窗</li>
<li><code>SessionPage</code>增加<code>set.encoding()</code>方法和<code>encoding</code>属性</li>
<li><option> 元素可以接受点击，操作更符合直觉</li>
<li><code>run_js()</code>、<code>run_js_loaded()</code>、<code>run_async_js()</code>方法增加<code>timeout</code>参数</li>
<li><code>run_async_js()</code>删除<code>timeout</code>参数</li>
<li><code>timeouts</code>的<code>implicit</code>改成<code>base</code></li>
<li><code>ActionChains</code>改成<code>Actions</code></li>
<li>动作链的移动方法增加<code>duration</code>参数</li>
<li>动作链增加<code>input()</code>方法</li>
<li>动作链<code>key_down()</code>和<code>key_up()</code>方法可接收按键名称文本</li>
<li>动作链<code>type()</code>方法<code>text</code>参数改为<code>keys</code></li>
<li><code>get_screenshot()</code>方法增加<code>name</code>属性，可指定文件名</li>
<li>元素的<code>get_screenshot()</code>方法增加<code>scroll_to_center</code>参数，截图前先滚动到页面正中</li>
<li><code>wait.new_tab()</code>方法成功时返回新标签页 id</li>
<li><code>tabs</code>不包含 F12 的窗口</li>
<li><code>DrissionPage.common</code>路径增加<code>wait_until()</code>方法，支持自定义组合等待条件</li>
</ul>
<hr />
<h2 id="_32">✅️ 问题修复</h2>
<ul>
<li>修复网络连接极不稳定时获取文档失败问题</li>
<li>修复相对定位<code>timeout</code>失效问题</li>
<li>修复 shadow root 内定位元素可能偏差问题</li>
<li>修复异域<code>ChromiumFrame</code>内部元素无法获取屏幕坐标的问题</li>
<li>修复相对路径插件加载失败的问题</li>
<li>所有循环增加超时设置，避免出现卡死</li>
<li>修复元素截图时窗口外部分空白问题</li>
<li>修复 Tab 没有继承 Page 下载路径的问题</li>
<li>修复 <code>&lt;iframe&gt;</code> 内元素获取 href 属性错误问题</li>
<li>修复 cookie 设置 expires 时的问题</li>
</ul>
<hr />
<h2 id="_33">✅️ 下一步计划</h2>
<ul>
<li>支持跨标签页监听数据包</li>
<li>模拟手机环境，支持触摸操作</li>
<li>支持随时修改浏览器代理</li>
<li>研究远程控制浏览器方案</li>
<li>支持 websocket 抓包</li>
<li>支持操作插件小窗</li>
<li>移动和点击时显示鼠标位置</li>
</ul>
<hr />
<h2 id="_34">✅️ 加快开发进度</h2>
<p>开源项目的推进有赖你的支持。欢迎投喂加速。</p>
<p><img alt="" src="../../imgs/code.jpg" /></p>





                
              </article>
            </div>
          
          
        </div>
        
          <button type="button" class="md-top md-icon" data-md-component="top" hidden>
            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12Z"/></svg>
            Back to top
          </button>
        
      </main>
      
        <footer class="md-footer">
  
    
      
      <nav class="md-footer__inner md-grid" aria-label="Footer" >
        
          
          <a href="../.." class="md-footer__link md-footer__link--prev" aria-label="Previous: 欢迎" rel="prev">
            <div class="md-footer__button md-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12Z"/></svg>
            </div>
            <div class="md-footer__title">
              <span class="md-footer__direction">
                Previous
              </span>
              <div class="md-ellipsis">
                欢迎
              </div>
            </div>
          </a>
        
        
          
          <a href="../3_2/" class="md-footer__link md-footer__link--next" aria-label="Next: 💥 3.2 功能介绍" rel="next">
            <div class="md-footer__title">
              <span class="md-footer__direction">
                Next
              </span>
              <div class="md-ellipsis">
                💥 3.2 功能介绍
              </div>
            </div>
            <div class="md-footer__button md-icon">
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4Z"/></svg>
            </div>
          </a>
        
      </nav>
    
  
  <div class="md-footer-meta md-typeset">
    <div class="md-footer-meta__inner md-grid">
      <div class="md-copyright">
  
  
    Made with
    <a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
      Material for MkDocs
    </a>
  
</div>
      
    </div>
  </div>
</footer>
      
    </div>
    <div class="md-dialog" data-md-component="dialog">
      <div class="md-dialog__inner md-typeset"></div>
    </div>
    
    <script id="__config" type="application/json">{"base": "../..", "features": ["navigation.top", "navigation.tracking", "toc.follow", "content.code.copy", "navigation.tabs", "navigation.tabs.sticky", "header.autohide", "navigation.footer"], "search": "../../assets/javascripts/workers/search.208ed371.min.js", "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}}</script>
    
    
      <script src="../../assets/javascripts/bundle.a51614de.min.js"></script>
      
        
          <script src="../../js/open_in_new_tab.js"></script>
        
      
    
  </body>
</html>